package dao

import (
	"context"
	"mall-portalv2/internal/model"
)

func (d *Dao) CreateCrowdFundingLog(ctx context.Context, insertModel model.SmsCrowdFundingLog) (model.SmsCrowdFundingLog, error) {
	tb := model.SmsCrowdFundingLog{}
	if err := d.db.WithContext(ctx).Table(tb.TableName()).Create(&insertModel).Error; err != nil {
		return insertModel, err
	}
	return insertModel, nil
}

func (d *Dao) QueryCrowdFundingLogWhereMemberIdAndOrdId(ctx context.Context, OrderId, MemberId int64) (model.SmsCrowdFundingLog, error) {
	tb := model.SmsCrowdFundingLog{}
	if err := d.db.WithContext(ctx).Table(tb.TableName()).Where("member_id = ? AND order_id = ?", MemberId, OrderId).First(&tb).Error; err != nil {
		return tb, err
	}
	return tb, nil
}

func (d *Dao) UpdateCrowdFundingLogWhereMemberIdAndOrdId(ctx context.Context, OrderId, MemberId int64, upadtes map[string]interface{}) error {
	tb := model.SmsCrowdFundingLog{}
	if err := d.db.WithContext(ctx).Table(tb.TableName()).Where("member_id = ? AND order_id = ?", MemberId, OrderId).Updates(upadtes).Error; err != nil {
		return err
	}
	return nil
}
